﻿@using Microsoft.Extensions.Options
@using reCAPTCHA.AspNetCore
@inject IOptions<RecaptchaSettings> options
@model reCAPTCHATest.Models.Account.AccountViewModel

@{
    ViewData["Title"] = "Login";
}

<h3>登录</h3>

<div class="row">
    <div class="col-xs-6">
        @if (ViewContext.ModelState.IsValid == false)
        {
            <div class="alert alert-danger">
                <strong>Error</strong>
                <div asp-validation-summary="All" class="danger"></div>
            </div>
        }
        <form class="form-horizontal" role="form" asp-action="Login" method="post">
            <input type="hidden" id="googleToken" name="googleToken"/>
            <div class="form-group">
                <label for="username" class="col-sm-2 control-label">用户名</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
                </div>
            </div>
            <div class="form-group">
                <label for="password" class="col-sm-2 control-label">密码</label>
                <div class="col-sm-10">
                    <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-default">登录</button>
                </div>
            </div>
        </form>
    </div>
</div>

@section Scripts
{
    <script src="https://www.recaptcha.net/recaptcha/api.js?render=@options.Value.SiteKey"></script>
    <script type="text/javascript">
        grecaptcha.ready(function () {
            grecaptcha.execute('@options.Value.SiteKey', { action: 'login' }).then(function (token) {
                //将Token写入隐藏域等等
                $("#googleToken").val(token);
            });
        });
    </script>
}
